﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Microsoft.VisualBasic.PowerPacks;

using MakeIT.MiraPark.Negocios;

namespace MiraPark
{
    public partial class FormColisaoSelect : Form
    {
        public FormColisaoSelect()
        {
            InitializeComponent();
        }

        public void MaisTipoColisoes(EventHandler eventHandler)
        {
            List<TipoColisaoVO> tipoColisaoVOs = ModelBO.getTipoColisoes();

            this.flowLayoutPanelMais.Controls.Clear();

            Shape[] shapes = new Shape[Math.Max(1,tipoColisaoVOs.Count)];
            int shapeIndex = 0;

            ShapeContainer myFirstShapeContainer = new ShapeContainer();
            myFirstShapeContainer.Location = new System.Drawing.Point(0, 0);
            myFirstShapeContainer.Margin = new System.Windows.Forms.Padding(0);
            myFirstShapeContainer.Name = "shapeContainerFirst";
            //myFirstShapeContainer.Shapes.AddRange(new Shape[] { ovalShape });
            myFirstShapeContainer.Size = new System.Drawing.Size(260, 390);
            myFirstShapeContainer.TabIndex = 0;
            myFirstShapeContainer.TabStop = false;
            
            Panel myFirstPanel = new Panel();
            myFirstPanel.SuspendLayout();
            myFirstPanel.BackgroundImage = global::MakeIT.MiraPark.Apresentacao.Properties.Resources.esquema_carro_v;
            myFirstPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            //myFirstPanel.Controls.Add(myLabel);
            myFirstPanel.Controls.Add(myFirstShapeContainer);
            myFirstPanel.Name = "panelFirst";
            myFirstPanel.Size = new System.Drawing.Size(260, 390);
            myFirstPanel.TabIndex = 24;
            this.flowLayoutPanelMais.Controls.Add(myFirstPanel);
            
            foreach (TipoColisaoVO tipoColisaoVO in tipoColisaoVOs)
            {
                Label myLabel = new Label();
                myLabel.Font = new System.Drawing.Font("Verdana", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                myLabel.Location = new System.Drawing.Point(3, 3);
                myLabel.Name = "label" + tipoColisaoVO.colisao;
                myLabel.AutoSize = true;
                myLabel.Size = new System.Drawing.Size(62, 49);
                myLabel.TabIndex = 15;
                myLabel.Text = tipoColisaoVO.colisao;

                OvalShape ovalShape = new OvalShape();
                ovalShape.Cursor = Cursors.Hand;
                ovalShape.BackColor = System.Drawing.Color.Red;
                ovalShape.FillColor = System.Drawing.Color.Red;
                ovalShape.FillGradientColor = System.Drawing.Color.Red;
                ovalShape.FillStyle = FillStyle.Percent50;
                ovalShape.Location = new System.Drawing.Point(tipoColisaoVO.avariaX, tipoColisaoVO.avariaY);
                ovalShape.Name = "ovalShape1";
                ovalShape.SelectionColor = System.Drawing.SystemColors.Control;
                ovalShape.Size = new System.Drawing.Size(tipoColisaoVO.avariaWidth, tipoColisaoVO.avariaHeight);
                ovalShape.Tag = tipoColisaoVO;
                ovalShape.Click += eventHandler;

                OvalShape ovalFirstShape = new OvalShape();
                ovalFirstShape.Cursor = Cursors.Hand;
                ovalFirstShape.BackColor = System.Drawing.Color.Red;
                ovalFirstShape.FillColor = System.Drawing.Color.Red;
                ovalFirstShape.FillGradientColor = System.Drawing.Color.Red;
                ovalFirstShape.FillStyle = FillStyle.Percent50;
                ovalFirstShape.Location = new System.Drawing.Point(tipoColisaoVO.avariaX, tipoColisaoVO.avariaY);
                ovalFirstShape.Name = "ovalShape1";
                ovalFirstShape.SelectionColor = System.Drawing.SystemColors.Control;
                ovalFirstShape.Size = new System.Drawing.Size(tipoColisaoVO.avariaWidth, tipoColisaoVO.avariaHeight);
                ovalFirstShape.Tag = tipoColisaoVO;
                ovalFirstShape.Click += eventHandler;
                shapes[shapeIndex++] = ovalFirstShape;
                
                ShapeContainer myShapeContainer = new ShapeContainer();
                myShapeContainer.Location = new System.Drawing.Point(0, 0);
                myShapeContainer.Margin = new System.Windows.Forms.Padding(0);
                myShapeContainer.Name = "shapeContainer1";
                myShapeContainer.Shapes.AddRange(new Shape[] { ovalShape });
                myShapeContainer.Size = new System.Drawing.Size(260, 390);
                myShapeContainer.TabIndex = 0;
                myShapeContainer.TabStop = false;

                Panel myPanel = new Panel();
                myPanel.SuspendLayout();
                myPanel.BackgroundImage = global::MakeIT.MiraPark.Apresentacao.Properties.Resources.esquema_carro_v;
                myPanel.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
                myPanel.Controls.Add(myLabel);
                myPanel.Controls.Add(myShapeContainer);
                myPanel.Name = "panel"+tipoColisaoVO.colisao;
                myPanel.Size = new System.Drawing.Size(260, 390);
                myPanel.TabIndex = 24;
 
                this.flowLayoutPanelMais.Controls.Add(myPanel);
                myPanel.ResumeLayout(false);

            }
            myFirstShapeContainer.Shapes.AddRange(shapes);

            groupBoxMais.Text = " Avarias: ";

            vScrollBar1.Minimum = 0;
            vScrollBar1.Maximum = tipoColisaoVOs.Count + 2;
            vScrollBar1.Value = 0;

        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            flowLayoutPanelMais.ScrollControlIntoView(flowLayoutPanelMais.Controls[e.NewValue]);

        }
        private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            flowLayoutPanelMais.ScrollControlIntoView(flowLayoutPanelMais.Controls[e.NewValue]);

        }

        private void buttonFecharJanelaMais_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
